<template>
  <div class="recommendedContent">
    <div class="recommendedContent-header">
      <h3>推荐内容</h3>
      <div class="songs_pages">
        <Pager :total="2" />
      </div>
    </div>
    <ul class="recommendedContent-main">
      <li v-for="item in contentList" :key="item.id">
        <a>{{ item.name }}</a>
      </li>
    </ul>
  </div>
</template>

<script>
import { reqRecommendedContent } from "@/api";
import Pager from "@/components/Pager";
import { mapState } from "vuex";
export default {
  name: "PopularSinger",
  components: {
    Pager,
  },
  mounted() {
    this.getRecommendedContent();
  },
  methods: {
    async getRecommendedContent(newValue) {
      const result = await reqRecommendedContent();
      this.recommendedList = result.result;
      const newArr = this.recommendedList.map((item) => {
        return {
          id: item.id,
          name: item.name,
        };
      });
      if (newValue === 1) {
        this.contentList = newArr.slice(0, 21);
      } else if (newValue === 2) {
        this.contentList = newArr.slice(21);
      }
    },
  },
  computed: {
    // 获取相应的页码
    ...mapState("page", ["pages"]),
  },
  watch: {
    pages: {
      immediate: true,
      handler(newValue) {
        this.getRecommendedContent(newValue);
      },
    },
  },
  data() {
    return {
      recommendedList: [],
      contentList: [],
    };
  },
};
</script>

<style lang="less" scoped>
.recommendedContent {
  width: 1000px;
  height: 252px;
  margin: 0 auto;
}

.recommendedContent-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 1000px;
  height: 50px;
  margin-top: 60px;
  margin-bottom: 20px;
}

.recommendedContent-header h3 {
  font-size: 25px;
  font-weight: normal;
  color: #000000;
  cursor: default;
}

.songs_pages {
  margin-right: 16px;
  cursor: pointer;
}

.prev,
.next {
  font-weight: 900;
  color: #cacaca;
  font-size: 14px;
}

.songs_pages_text {
  margin-left: 5px;
  margin-right: 5px;
  font-size: 14px;
  color: #000;
}

.recommendedContent-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  width: 1000px;
  height: 116px;
}

.recommendedContent-main li {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 139.8px;
  height: 50px;
  margin-right: 3px;
  background: rgb(177 179 185 / 10%);
  color: #000;
  font-style: 12px;
  text-align: center;
  box-sizing: border-box;
  cursor: pointer;
  margin-bottom: 7px;
}

.recommendedContent-main li:hover a {
  color: #00a9ff;
}
</style>
